import requests
import os


# 获取B站热门榜图片
url = 'https://api.bilibili.com/x/web-interface/popular'

for x in range(0,3):
  bilibili_url = requests.get( url, params = { 'ps': 20,'pn': x + 1 })
  if bilibili_url.status_code != 200:
    print('网站访问错误')
  else:
    data_list = bilibili_url.json()['data']['list']
    for list_info in data_list:
      print(list_info['pic'])
      name = os.path.basename(list_info['pic'])
      f = open(f'pic/{name}','wb')
      img = requests.get(list_info['pic'])
      f.write(img.content)

f.close()
  